<?php
/**
 * @Author: Wang Chunsheng 2192138785@qq.com
 * @Date:   2020-03-02 08:20:27
 * @Last Modified by:   Wang Chunsheng 2192138785@qq.com
 * @Last Modified time: 2020-03-02 08:25:05
 */
 

 
namespace app\modules\diandi_shop\models\searchs;

use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\modules\diandi_shop\models\DdDelivery;

/**
 * DdDeliverySearch represents the model behind the search form of `common\models\DdDelivery`.
 */
class DdDeliverySearch extends DdDelivery
{
    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['delivery_id', 'method', 'sort', 'wxapp_id', 'create_time', 'update_time'], 'integer'],
            [['name'], 'safe'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = DdDelivery::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'delivery_id' => $this->delivery_id,
            'method' => $this->method,
            'sort' => $this->sort,
            'wxapp_id' => $this->wxapp_id,
            'create_time' => $this->create_time,
            'update_time' => $this->update_time,
        ]);

        $query->andFilterWhere(['like', 'name', $this->name]);

        return $dataProvider;
    }
}
